/**
 * Author: ligj@mapbar.com
 * Create Time: 2018/01/12 10:41
 * Description:
 */

import VueEvents from 'vue-events'
import Vue from "vue"

const eventsName = '_events_vue_events';

Vue.use(VueEvents);

Vue.mixin({
    methods: {
        $bind(event, callback){
            this[eventsName].push({
                event, callback
            });
            this.$events.$on(event, callback);
        },
        $fire(event, data){
            this.$events.$emit(event, data);
        }
    },
    beforeCreate(){
        this[eventsName] = [];
    },
    destroyed(){
        this[eventsName].forEach(event => {
            this.$events.$off(event.event, event.callback);
        })
    }
});

export default {};
